/**
 * 修复因为当前屏幕分辨率和设置的屏幕分辨率不一致导致的测绘偏移以及dom渲染失真的问题
 */
const setContainerLocation = (dom, domHeight, DomWidth) => {
  if (!dom) return;
  let height = domHeight || parseFloat(dom.getBoundingClientRect().height);
  let width = DomWidth || parseFloat(dom.getBoundingClientRect().width);
  let transformHeight = parseFloat(dom.offsetHeight);
  let transformWidth = parseFloat(dom.offsetWidth);
  //  因为数据类型可能不同，所有所以使用 ==
  if (height == transformHeight && width == transformWidth) {
    return
  }
  //  计算反转比例
  let widthScale = transformWidth / width;
  let heightScale = transformHeight / height;
  //  反比例缩放
  dom.style.transform = `scale(${widthScale}, ${heightScale})`;
  //  重新构建大小
  dom.style.height = `${transformHeight / heightScale}px`;
  dom.style.width = `${transformWidth / widthScale}px`;
  //  重新定位
  let left = isNaN(parseInt(dom.style.left)) ? 0 : parseInt(dom.style.left);
  let top = isNaN(parseInt(dom.style.top)) ? 0 : parseInt(dom.style.top);
  dom.style.left = `${left - ((width - width * widthScale) / 2)}px`;
  dom.style.top = `${top - ((height - height * heightScale) / 2)}px`;
  dom.style.position = 'absolute'
};

export { setContainerLocation }
